<template>
  <div class="main">
    <div class="out-box">
      <div class="avatar">
        <el-avatar :src="avatar"></el-avatar>
      </div>
      <div class="info">
        <div class="name">玩家:{{ name }}</div>
        <div class="return">总收益:{{ value }}</div>
      </div>
    </div>
    <!-- <div class="chart" ref="chart"></div> -->
    <div class="revenue-list">详细清单：</div>
  </div>
</template>

<script>
export default {
  props: ['pydata', 'name','avatar'],
  data: function () {
    return {
      value: 0,
      ydata: [-50, 100, -50, 100, 200],
    };
  },
  mounted: function () {
    this.ydata = this.pydata;
    this.initCharts();
  },
  methods: {
    initCharts() {
      let myChart = this.$echarts.init(this.$refs.chart);
      var option;
      option = {
        xAxis: {
          data: ["商品1", "商品2", "商品3", "商品4", "商品5"],
        },
        yAxis: {},
        series: [
          {
            type: "bar",
            data: this.ydata,
            barWidth: '40%'
          },
        ],
        color: "#db4240"
      };
      option && myChart.setOption(option);
    },
  },
  watch: {
    pydata: function (newData, oldData) {
      this.ydata = newData;
      this.value = 0;
      for(let i=0;i<this.ydata.length;i++){
        this.value += this.ydata[i];
      }
      this.initCharts();
    }
  }
};
</script>

<style lang="less"  scoped>
.main {
  margin: 5px;
  box-sizing: border-box;
  padding: 5px;
  border: 3px solid #b9c6ff;
  border-radius: 15px;
}

.out-box {
  display: flex;
  width: 170px;
  height: 82px;
  display: flex;
  align-content: center;
  justify-content: center;

  .avatar {
    height: 100%;
    display: flex;
    align-items: center;
  }

  .info {
    width: 60%;

    .name,
    .return {
      font-size: 1.3em;
      font-weight: bold;
      line-height: 2em;
    }
  }
}

.chart {
  height: 60px;
}
</style>